package com.zhang.set;

import com.zhang.map.Map;
import com.zhang.map.TreeMap;

/**
 * @author 张吉鑫
 * @Description 用treeMap实现
 * @date 2021/3/24 18:08
 */
public class NewTreeSet<E> implements Set<E> {

    Map<E , Object> treeMap= new TreeMap<>();

    @Override
    public int size() {
        return treeMap.size();
    }

    @Override
    public boolean isEmpty() {
        return treeMap.size() == 0;
    }

    @Override
    public void clear() {
        treeMap.clear();
    }

    @Override
    public boolean contains(E element) {
        return treeMap.containsKey(element);
    }

    @Override
    public void add(E element) {
        treeMap.put(element, null);
    }

    @Override
    public void remove(E element) {
        treeMap.remove(element);
    }

    @Override
    public void traversal(Visitor<E> visitor) {
        treeMap.traversal(new Map.Visitor<E, Object>() {
            @Override
            public boolean visit(E key, Object value) {
                return visitor.visit(key);
            }
        });
    }
}
